{% extends "base_generic.html" %}

{% block title %}My Borrowed Books - Local Library{% endblock %}

{% block content %}
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1><i class="bi bi-bookmark"></i> My Borrowed Books</h1>
            <p class="text-muted">Manage your borrowed books</p>
        </div>
    </div>

    {% if borrowrecord_list %}
        <div class="row g-4">
            {% for record in borrowrecord_list %}
                <div class="col-md-6">
                    <div class="card">
                        <div class="card-header d-flex justify-content-between align-items-center">
                            <h6 class="mb-0">{{ record.book_instance.book.title }}</h6>
                            {% if record.is_overdue %}
                                <span class="badge bg-danger">Overdue</span>
                            {% else %}
                                <span class="badge bg-success">Active</span>
                            {% endif %}
                        </div>
                        <div class="card-body">
                            <div class="row mb-2">
                                <div class="col-sm-4"><strong>Author:</strong></div>
                                <div class="col-sm-8">{{ record.book_instance.book.author }}</div>
                            </div>

                            <div class="row mb-2">
                                <div class="col-sm-4"><strong>Borrowed:</strong></div>
                                <div class="col-sm-8">{{ record.borrow_date|date:"M j, Y" }}</div>
                            </div>

                            <div class="row mb-2">
                                <div class="col-sm-4"><strong>Due Date:</strong></div>
                                <div class="col-sm-8">
                                    {{ record.due_date }}
                                    {% if record.is_overdue %}
                                        <span class="text-danger">
                    <i class="bi bi-exclamation-triangle"></i> Overdue
                  </span>
                                    {% endif %}
                                </div>
                            </div>

                            <div class="row mb-3">
                                <div class="col-sm-4"><strong>Copy ID:</strong></div>
                                <div class="col-sm-8">
                                    <code>{{ record.book_instance.id|slice:":8" }}...</code>
                                </div>
                            </div>

                            <div class="d-flex justify-content-between">
                                <a href="{{ record.book_instance.book.get_absolute_url }}"
                                   class="btn btn-outline-primary btn-sm">
                                    <i class="bi bi-eye"></i> View Book
                                </a>
                                <a href="{% url 'return-book' record.id %}" class="btn btn-success btn-sm">
                                    <i class="bi bi-arrow-return-left"></i> Return Book
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    {% else %}
        <div class="text-center py-5">
            <i class="bi bi-bookmark display-1 text-muted"></i>
            <h3 class="mt-3">No borrowed books</h3>
            <p class="text-muted">You haven't borrowed any books yet.</p>
            <a href="{% url 'books' %}" class="btn btn-primary">
                <i class="bi bi-search"></i> Browse Books
            </a>
        </div>
    {% endif %}

{% endblock %} 